clear 
use tax_credit_value, replace


*Use this comment to create tables for four and nine percent credit projects, or construction type separately (used to create Table 4)
*keep if nineper==1
*keep if constructiontype=="A&R"

*note that there are two versions. The one I'm using is from the CTCAC website spreadsheet
gen fedtaxcredits_real=fedaward/CPI
gen statetaxcredits_real=stateaward/CPI

*Federal Tax Credit amount is awarded every year for ten year. 
gen discountfactor=1/(1+treasury10)
gen PV_fedcredit=fedtaxcredits_real*((1-discountfactor^10)/(1-discountfactor))

*The State Tax Credits is the total amount, but it is awarded over four years.
*I'll divided the total by four and then do the present value.
gen annualstatecredit_real=statetaxcredits_real/4
gen PV_statecredit=annualstatecredit_real*((1-discountfactor^4)/(1-discountfactor))

**collapse and calculate per unit values
collapse (sum) liunits PV_* , by(nineperc)


*Sum up total units
egen totalliunits=sum(liunits)

*Divide each credit type by the total units (nineperc==1 is competitive, nineperc==0 is noncompetitive)
gen credit_per_unit=PV_fedcredit/totalliunits


*Get total average state credit and divide by total units
egen PVtotalstatecredit=sum(PV_statecredit)
gen state_credit_per_unit=PVtotalstatecredit/totalliunits

format %16.0g *
